package com.woniu.exception;


import com.woniu.util.JsonResult;
import io.jsonwebtoken.ExpiredJwtException;
import io.jsonwebtoken.SignatureException;
import io.netty.handler.codec.CodecException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class MyExceptionHandler {
    @ExceptionHandler(ExpiredJwtException.class)
    public JsonResult expiredJwtException(ExpiredJwtException e) {
        return JsonResult.build(501, e.getMessage(), null);
    }

    @ExceptionHandler(SignatureException.class)
    public JsonResult signatureException(SignatureException e) {
        return JsonResult.build(502, e.getMessage(), null);
    }

    @ExceptionHandler(CodecException.class)
    public JsonResult codecException(CodecException e) {
        return JsonResult.build(500, e.getMessage(), null);
    }

    @ExceptionHandler(RuntimeException.class)
    public JsonResult runtimeException(RuntimeException e) {
        return JsonResult.build(500, e.getMessage(), null);
    }
}
